package cn.kgc.controller;

import cn.kgc.pojo.Lxdetail;
import cn.kgc.pojo.Lxdetail2;
import cn.kgc.pojo.Lxpay;
import cn.kgc.service.Lxdetail2Service;
import cn.kgc.service.LxpayService;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 木子
 * @date: 2022/2/16
 * @description:
 */
@Controller
@RequestMapping("/xc")
public class LXCGLController {

    @Resource
    private LxpayService ls;
    @Resource
    private Lxdetail2Service lse;

    @RequestMapping("/go")
    public String go() {
        return "/lxmine/xinchoufafang";
    }

    @RequestMapping("/add")
    @ResponseBody
    public int add() {
        return ls.newAdd();
    }

    @RequestMapping("/sel")
    @ResponseBody
    public String selAll() {
        List<Lxpay> list = ls.selAll();
        return JSON.toJSONString(list);
    }

    @RequestMapping("/byId/{fid}/{lid}/{state}")
    public String selById(@PathVariable int fid,
                          @PathVariable int lid,
                          @PathVariable int state, Model model) {
        boolean flag = false;
        if (state==0){
            flag =true;
        }
        List<Lxdetail2> list = lse.query(fid, lid);
        //System.out.println("list = " + list);
        model.addAttribute("show", list);
        model.addAttribute("pa",flag);
        return "lxmine/xinchoufafangxiangqin2";
    }

    @RequestMapping("/detail/{id}")
    public String detail(@PathVariable int id, Model model) {
        List<Lxdetail> list = ls.selById(id);
        System.out.println("list = " + list);
        model.addAttribute("lx", list);
        return "lxmine/xinchoufafangxiangqin";
    }

    @RequestMapping("/update")
    @ResponseBody
    public void update(Lxdetail2 ld) {
        System.out.println("ld = " + ld);
        lse.updateById(ld);

    }

    @RequestMapping("/update2")
    @ResponseBody
    public void upadet2(Lxdetail ll){

        int i = lse.totalById(ll);
        ll.setActual(i);
        System.out.println("ll哈哈哈哈哈 = " + ll);
        lse.update2ById(ll);
    }

//    @RequestMapping("/add3/{id}")
//    @ResponseBody
//    public String ad(@PathVariable int id){
//        List<Lxdetail2> list = lse.query(id);
//        return JSON.toJSONString(list);
//    }
//    @RequestMapping("/sel3/{id}")
//    @ResponseBody
//    public String selAll3(@PathVariable int id){
//        List<Lxdetail2> list = lse.selById(id);
//        return JSON.toJSONString(list);
//    }
}
